/**
 *  Java Api For Ecco Generated Applications 
 *  
 *  Copyright (C) 2000  by PDTec GmbH 
 *
 * @author  Michael Weirich
 */

package pdtec.ecco.inst;

import pdtec.ecco.meta.Entity;
import pdtec.ecco.meta.EccoException;

/** 
 * This class provides a way to iterate over EXPRESS entity instances. The PopulationIterator
 * may be applied to objects of class Instance only.
 */
public class PopulationIterator {

    /** Id of the population iterator. This field value is set automatically. */  
    protected long id; 
    
    /** Associated Application id. This field value is set automatically.  */
    protected int appId; 
    
    /** The constructor takes a entity for initializing. */
    public  PopulationIterator(Entity entity ){ 
	try {
	    create(entity);
	} catch (EccoException e) {
	    System.out.println(e.toString());
	} // try
    } // constructor 
    
    /** Internal creation of the iterator.
     * @exception pdtec.ecco.meta.EccoException in case an error occurs
     */
    protected native synchronized void create(Entity entity) throws EccoException;
    
    /** Shifts iterator to next position.
     * @exception pdtec.ecco.meta.EccoException in case an error occurs
     */ 
    public native synchronized void  next() throws EccoException;
    
    /** Determines wether iterator reached end of population or not.
     * @exception pdtec.ecco.meta.EccoException in case an error occurs
     */
    public native synchronized boolean end() throws EccoException;
  
    /** Resets iterator position to the start.
     * @exception pdtec.ecco.meta.EccoException in case an error occurs
     */
    public native synchronized void reset() throws EccoException;
    
    /** Deletes the iterator object.
     * @exception pdtec.ecco.meta.EccoException in case an error occurs
     */  
    public native synchronized void delete() throws EccoException;
    
    /** Returns the instance, the iterator currently points at.
     * @exception pdtec.ecco.meta.EccoException in case an error occurs
     */
    public native synchronized Instance current() throws EccoException;
    
    /** Finalizes the PopulationIterator instance. */
    protected void finalize() {
	try{
	    delete();
	} catch(Exception e) {
	    System.out.println(e.toString());
	} // catch 
    } // finalize
    
} // class PopulationIterator







